{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Maximum Score After Splitting a String"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: maxScore"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #分割字符串的最大得分"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个由若干 0 和 1 组成的字符串 <code>s</code> ，请你计算并返回将该字符串分割成两个 <strong>非空</strong> 子字符串（即&nbsp;<strong>左</strong> 子字符串和 <strong>右</strong> 子字符串）所能获得的最大得分。</p>\n",
    "\n",
    "<p>「分割字符串的得分」为 <strong>左</strong> 子字符串中 <strong>0</strong> 的数量加上 <strong>右</strong> 子字符串中 <strong>1</strong> 的数量。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = &quot;011101&quot;\n",
    "<strong>输出：</strong>5 \n",
    "<strong>解释：</strong>\n",
    "将字符串 s 划分为两个非空子字符串的可行方案有：\n",
    "左子字符串 = &quot;0&quot; 且 右子字符串 = &quot;11101&quot;，得分 = 1 + 4 = 5 \n",
    "左子字符串 = &quot;01&quot; 且 右子字符串 = &quot;1101&quot;，得分 = 1 + 3 = 4 \n",
    "左子字符串 = &quot;011&quot; 且 右子字符串 = &quot;101&quot;，得分 = 1 + 2 = 3 \n",
    "左子字符串 = &quot;0111&quot; 且 右子字符串 = &quot;01&quot;，得分 = 1 + 1 = 2 \n",
    "左子字符串 = &quot;01110&quot; 且 右子字符串 = &quot;1&quot;，得分 = 2 + 1 = 3\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = &quot;00111&quot;\n",
    "<strong>输出：</strong>5\n",
    "<strong>解释：</strong>当 左子字符串 = &quot;00&quot; 且 右子字符串 = &quot;111&quot; 时，我们得到最大得分 = 2 + 3 = 5\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = &quot;1111&quot;\n",
    "<strong>输出：</strong>3\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= s.length &lt;= 500</code></li>\n",
    "\t<li>字符串 <code>s</code> 仅由字符 <code>&#39;0&#39;</code> 和 <code>&#39;1&#39;</code> 组成。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [maximum-score-after-splitting-a-string](https://leetcode.cn/problems/maximum-score-after-splitting-a-string/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [maximum-score-after-splitting-a-string](https://leetcode.cn/problems/maximum-score-after-splitting-a-string/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"011101\"', '\"00111\"', '\"1111\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bagOfTokensScore(self, tokens: List[int], power: int) -> int:\n",
    "        tokens.sort()\n",
    "        left, right = 0, len(tokens)-1\n",
    "        maxScore = score = 0\n",
    "        while left <= right:\n",
    "            if power < tokens[left] and score <= 0:\n",
    "                return maxScore\n",
    "            else:\n",
    "                if power >= tokens[left]:\n",
    "                    power -= tokens[left]\n",
    "                    left += 1\n",
    "                    maxScore = max(maxScore, score := score + 1)\n",
    "                else:\n",
    "                    while score > 0 and power < tokens[left]:\n",
    "                        power += tokens[right]\n",
    "                        right -= 1\n",
    "                        score -= 1\n",
    "        return maxScore\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def bagOfTokensScore(self, tokens: List[int], power: int) -> int:\n",
    "        tokens.sort()\n",
    "        n = len(tokens)\n",
    "        psum = [0] * (n + 1)\n",
    "        for i in range(n): psum[i+1] = psum[i] + tokens[i]\n",
    "\n",
    "        def f(L, R, P):\n",
    "            l, r = L, R + 1\n",
    "            while l + 1 < r:\n",
    "                mid = (l + r) // 2\n",
    "                if psum[mid] - psum[L] <= P:\n",
    "                    l = mid\n",
    "                else:\n",
    "                    r = mid\n",
    "            return l - L\n",
    "\n",
    "        l, r = 0, n\n",
    "        maxScore = 0\n",
    "        while l < r:\n",
    "            maxScore = max(maxScore, f(l, r, power))\n",
    "            if power >= tokens[l]:\n",
    "                power = power - tokens[l] + tokens[r-1]\n",
    "                l += 1\n",
    "                r -= 1\n",
    "            else:\n",
    "                break\n",
    "\n",
    "        return maxScore\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        ans = 0\n",
    "        for i in range(1, n):\n",
    "            cnt = 0\n",
    "            for j in range(i):\n",
    "                if s[j] == '0':\n",
    "                    cnt += 1\n",
    "            for j in range(i, n):\n",
    "                if s[j] == '1':\n",
    "                    cnt += 1\n",
    "            ans = max(ans, cnt)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:n].count(\"0\")+s[n:].count(\"1\") for n in range(1,len(s)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans = s[:1].count('0') + s[1:].count('1')\n",
    "        for i in range(1, len(s)):\n",
    "            score = s[:i].count('0') + s[i:].count('1')\n",
    "            ans = max(ans, score)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count(\"0\")+s[i:].count(\"1\") for i in range(1,len(s))) # 至少从s[1]位开始分割"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        total_sum = 0\n",
    "        for index in range(1,len(s)):\n",
    "            left_len = s[:index].count('0')\n",
    "            right_len = s[index:].count('1')\n",
    "            total_sum = max(total_sum, left_len+right_len)\n",
    "        return total_sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans=0\n",
    "        for i in range(1,len(s)):\n",
    "            step=0\n",
    "            for j in range(i):\n",
    "                if int(s[j])==0 :step+=1\n",
    "            for k in range(i,len(s)):\n",
    "                if int(s[k])==1 :step+=1\n",
    "            if step>=ans :\n",
    "                ans=step\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        l = len(s)\n",
    "        left = ''\n",
    "        right = ''\n",
    "        temp = 0\n",
    "        max_t = 0\n",
    "        for i in range(1 , l):\n",
    "            left = s[0 : i]\n",
    "            right = s[i :]\n",
    "            temp =  left.count('0') + right.count('1')\n",
    "            if temp > max_t:\n",
    "                max_t = temp\n",
    "        return max_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        str1,str2=s[0],s[1:]\n",
    "        ans=0 if str1=='1' else 1\n",
    "        for c in str2:\n",
    "            if c=='1':\n",
    "                ans+=1\n",
    "        res=ans\n",
    "        for c in str2[:-1]:\n",
    "            if c=='0':\n",
    "                ans+=1\n",
    "            else:\n",
    "                ans-=1\n",
    "            if res<ans:\n",
    "                res=ans\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n = 0\n",
    "        for i in range(1,len(s)):\n",
    "            left_s = s[:i]\n",
    "            right_s = s[i:]\n",
    "            val = left_s.count(\"0\") + right_s.count(\"1\")\n",
    "            if val > n:\n",
    "                n = val\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        one,zero = s.count('1'), 0\n",
    "        res = 0\n",
    "        for i in s[:-1]:\n",
    "            if i == '0':\n",
    "                zero += 1\n",
    "            else:\n",
    "                one -= 1\n",
    "            if zero + one > res:\n",
    "                res = zero + one\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        i = 1\n",
    "        sums = 0\n",
    "        while i < len(s):\n",
    "            int2 = int1  = 0\n",
    "            for j in s[0:i]:\n",
    "                if int(j) == 0:\n",
    "                    int1 += 1\n",
    "            for n in s[i:len(s)]:\n",
    "                int2 += int(n)\n",
    "            if int1 == len(s):\n",
    "                return 1\n",
    "            elif int1 + int2 > sums:\n",
    "                sums = int1 + int2\n",
    "            i += 1\n",
    "        return sums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n=len(s)\n",
    "        k=1\n",
    "        ans=0\n",
    "        while k<n:\n",
    "            q=s[0:k]\n",
    "            h=s[k:n+1]\n",
    "            k+=1\n",
    "            i=q.count('0')\n",
    "            j=h.count('1')\n",
    "            ans=max(ans,i+j)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        i = 1\n",
    "        n = len(s)\n",
    "        result = []\n",
    "        for i in range(1, n):\n",
    "            left_str = s[: i]\n",
    "            right_str = s[i : n]\n",
    "            num = left_str.count(\"0\") + right_str.count(\"1\")\n",
    "            result.append(num)\n",
    "            \n",
    "        return max(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        res = 0\n",
    "        for i in range(n-1):\n",
    "            left_str = s[0:i+1]\n",
    "            right_str = s[i+1:n+1]\n",
    "            #print(left_str,right_str)\n",
    "            left_str_cnt0 = 0\n",
    "            right_str_cnt1 = 0\n",
    "            for l in range(len(left_str)):\n",
    "                if left_str[l] == '0':\n",
    "                    left_str_cnt0 += 1\n",
    "            for k in range(len(right_str)):\n",
    "                if right_str[k] == '1':\n",
    "                    right_str_cnt1 += 1\n",
    "            res_tmp = left_str_cnt0 + right_str_cnt1\n",
    "            #print(res_tmp)\n",
    "            if res_tmp > res:\n",
    "                res = res_tmp\n",
    "                #print(res)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count('0')+s[i:].count('1') for i in range(1,len(s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count('0') + s[i:].count('1') for i in range(1, len(s)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        k = 0; k_ = 0\n",
    "        for i in range(0,len(s)):\n",
    "            if s[i] == \"1\":\n",
    "                k+=1\n",
    "            else:\n",
    "                k_+=1\n",
    "        # k为1 k_为0\n",
    "\n",
    "        ans = 0\n",
    "        o = 0\n",
    "        for i in range(0,len(s)-1):\n",
    "            if s[i] == \"1\":\n",
    "                k -=1\n",
    "            else:\n",
    "                o+=1\n",
    "            ans = max(ans,o+k)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        total_sum = 0\n",
    "        for index in range(1,len(s)):\n",
    "            left_len = 0\n",
    "            right_len = 0\n",
    "            for left_index in range(index):\n",
    "                # print(left_index)\n",
    "                if s[left_index] == '0':\n",
    "                    left_len+=1\n",
    "            for right_index in range(index,len(s)):\n",
    "                # print(right_index)\n",
    "                if s[right_index] == '1':\n",
    "                    right_len+=1\n",
    "            total_sum = max(total_sum, left_len+right_len)\n",
    "        return total_sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        # 暴力法\n",
    "        lenth = len(s)\n",
    "        score = 0\n",
    "        for i in range(1,lenth):\n",
    "            left = s[:i]\n",
    "            right = s[i:]\n",
    "            score = max(left.count('0') + right.count('1'),score)\n",
    "        return score\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        result=0\n",
    "        n=len(s)\n",
    "        for i in range(1,n):\n",
    "            x1=s[:i]\n",
    "            x2=s[i:]\n",
    "            single=x1.count(\"0\")+x2.count(\"1\")\n",
    "            if single>result:\n",
    "                result=single\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans=0\n",
    "        for i in range(1,len(s)):\n",
    "            ans=max(ans,s[0:i].count('0')+s[i:len(s)].count('1'))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        one = 0\n",
    "        for i in s:\n",
    "            if i == '1':\n",
    "                one += 1\n",
    "        lzero,lone = 0,0\n",
    "        res = 0\n",
    "        for i in range(len(s)-1):\n",
    "            if s[i] == '0':\n",
    "                lzero += 1\n",
    "            else:\n",
    "                lone += 1\n",
    "            res = max(res,lzero + (one - lone))\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        maxx = 0\n",
    "        for i in range(1, len(s)):\n",
    "            left = s[:i]\n",
    "            right = s[i:]\n",
    "            l0 = left.count('0')\n",
    "            r1 = right.count('1')\n",
    "            if l0 + r1 >= maxx:\n",
    "                maxx = l0 + r1\n",
    "        return maxx\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "         n, presum, ans = len(s), 0, -inf\n",
    "         for i in range(n):\n",
    "            if i and (cur := presum * 2 - i) > ans:\n",
    "                ans = cur\n",
    "            presum += s[i] == \"0\"\n",
    "         return ans + n - presum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans = 0\n",
    "        for i in range(1, len(s)):\n",
    "            ls, rs = \"\", \"\"\n",
    "            x = 0\n",
    "            ls = s[:i]\n",
    "            rs = s[i:]\n",
    "            for j in ls:\n",
    "                if j == \"0\":\n",
    "                    x += 1\n",
    "            for k in rs:\n",
    "                if k == \"1\":\n",
    "                    x += 1\n",
    "            ans = x if x > ans else ans\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count('0')+s[i:].count('1') for i in range(1,len(s)))\n",
    "\n",
    "        #s[:i]表示从最开始到i-1\n",
    "        #s[i:]表示从i到最后\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n, presum, ans = len(s), 0, -inf\n",
    "        for i in range(n):\n",
    "            # cur = presum + (n - i - final_presum + presum) = presum * 2 - i + (n - final_presum)\n",
    "            if i and (cur := presum * 2 - i) > ans:\n",
    "                ans = cur\n",
    "            presum += s[i] == \"0\"\n",
    "        return ans + n - presum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count(\"0\")+s[i:].count(\"1\") for i in range(1,len(s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count('0') + s[i:].count('1') for i in range(1, len(s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        sub_left = \"0\"\n",
    "        sub_right = \"1\"\n",
    "        a=[]\n",
    "        for i in range(1, n):\n",
    "            left_half = s[0:i]\n",
    "            right_half = s[i:n]\n",
    "            sum_count = left_half.count(sub_left) + right_half.count(sub_right)\n",
    "            a.append(sum_count)\n",
    "        return max(a)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        score = list()  \n",
    "        for i in range(1,len(s)):\n",
    "            a = s[:i].count('0')\n",
    "            b = s[i:].count('1')\n",
    "            c = a + b\n",
    "            score.append(c)\n",
    "        return max(score)\n",
    "            \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        total0 = 0\n",
    "        total1 = 0\n",
    "        for i in s:\n",
    "            if i == \"0\":\n",
    "                total0 += 1\n",
    "            else:\n",
    "                total1 += 1\n",
    "        start=0\n",
    "        left = 0\n",
    "        right = total1\n",
    "        res = 0\n",
    "        while start<len(s)-1:\n",
    "            if s[start] == \"0\":\n",
    "                left += 1\n",
    "            else:\n",
    "                right -= 1\n",
    "            start += 1\n",
    "            res = max(res,left+right)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        cnt_map = collections.Counter(s)\n",
    "        zero_cnt, one_cnt = 0, 0\n",
    "        score = 0\n",
    "        for c in s[:-1]:\n",
    "            if c == '0':\n",
    "                zero_cnt += 1\n",
    "            else:\n",
    "                one_cnt += 1\n",
    "            score = max(score, zero_cnt + cnt_map.get('1', 0) - one_cnt)\n",
    "        return score\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n=len(s)\n",
    "        sum=0\n",
    "        ans=0\n",
    "        for i in range(n-1):\n",
    "           ans=max(ans,s[:i+1].count('0')+s[i+1:].count('1'))\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        num_of_0 = s.count('0')\n",
    "        num_of_1 = s.count('1')\n",
    "\n",
    "        left_0 = 0\n",
    "        left_1 = 0\n",
    "\n",
    "        score = 0\n",
    "        \n",
    "        for i in range(0, len(s)-1):\n",
    "            if s[i] == '0':\n",
    "                left_0 += 1\n",
    "            else:\n",
    "                left_1 += 1\n",
    "            \n",
    "            right_1 = num_of_1 - left_1\n",
    "            if left_0 + right_1 > score:\n",
    "                score = left_0 + right_1\n",
    "        \n",
    "        return score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, string: str) -> int:\n",
    "        left = int(string[0] == '0')\n",
    "        right = sum(1 for x in string[1:] if x == '1')\n",
    "        score = left + right\n",
    "        for i in range(1, len(string) - 1):\n",
    "            if string[i] == '0':\n",
    "                left += 1\n",
    "            else:\n",
    "                right -= 1\n",
    "            if left + right > score:\n",
    "                score = left + right\n",
    "        return score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans = 0\n",
    "        for i in range(len(s)-1):\n",
    "            s_l = s[:i+1]\n",
    "            s_r = s[i+1:]\n",
    "            s_l_0 = 0\n",
    "            s_r_1 = 0\n",
    "            for x in s_l:\n",
    "                if x == \"0\":\n",
    "                    s_l_0 += 1\n",
    "            for y in s_r:\n",
    "                if y == \"1\":\n",
    "                    s_r_1 += 1\n",
    "            number = s_l_0 + s_r_1\n",
    "            if number > ans:\n",
    "                ans = number\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max([2*s[:i].count('0')+s.count('1')-i for i in range(1,len(s))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n = 1\n",
    "        res = []\n",
    "        left = []\n",
    "        right = []\n",
    "        while n < len(s):\n",
    "            left = s[:n]\n",
    "            right = s[n:]\n",
    "            i = left.count(\"0\") + right.count(\"1\")\n",
    "            res.append(int(i))\n",
    "            n += 1\n",
    "        \n",
    "        return max(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        k = i = 1\n",
    "        sums = 0\n",
    "        while k < len(s):\n",
    "            int2 = int1  = 0\n",
    "            for j in s[0:i]:\n",
    "                if int(j) == 0:\n",
    "                    int1 += 1\n",
    "            for n in s[i:len(s)]:\n",
    "                int2 += int(n)\n",
    "            if int1 == len(s):\n",
    "                return 1\n",
    "            elif int1 + int2 > sums:\n",
    "                sums = int1 + int2\n",
    "            k += 1\n",
    "            i += 1\n",
    "        return sums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        a = 0\n",
    "        sums = 0\n",
    "        maxx = 0\n",
    "        for i in range(len(s)-1):\n",
    "            a = sum([y for x,y in collections.Counter(s[:i+1]).items() if x=='0'])\n",
    "            a += sum([y for x,y in collections.Counter(s[i+1:]).items() if x=='1'])\n",
    "            maxx = max(maxx , a)\n",
    "        return maxx\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        points = []\n",
    "        for i in range(1,len(s)):\n",
    "            a = s[:i].count(\"0\")\n",
    "            b = s[i:].count(\"1\")\n",
    "            x = a+b\n",
    "            points.append(x)\n",
    "        return max(points)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        total_sum = 0\n",
    "        start_index = 0\n",
    "        for i in range(len(s)):\n",
    "            if s[i] == 0:\n",
    "                start_index+=1\n",
    "        if start_index == 0:\n",
    "            start_index = 1\n",
    "        if start_index == len(s)-1:\n",
    "            start_index = len(s)-2\n",
    "        for index in range(1,len(s)):\n",
    "            left_len = 0\n",
    "            right_len = 0\n",
    "            for left_index in range(index):\n",
    "                # print(left_index)\n",
    "                if s[left_index] == '0':\n",
    "                    left_len+=1\n",
    "            for right_index in range(index,len(s)):\n",
    "                # print(right_index)\n",
    "                if s[right_index] == '1':\n",
    "                    right_len+=1\n",
    "            if total_sum < left_len + right_len:\n",
    "                total_sum = left_len + right_len\n",
    "        return total_sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count(\"0\")+s[i:].count(\"1\") for i in range (1,len(s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        A = []\n",
    "        for i in range(1,len(s)):\n",
    "            L = s[:i]\n",
    "            R = s[i:]\n",
    "            A.append(L.count('0')+R.count('1'))\n",
    "        return max(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        count_1 = s.count('1')\n",
    "        return max([2*s[:i].count('0')+count_1-i for i in range(1,len(s))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n=len(s)\n",
    "        max_score=0\n",
    "        for i in range(n-1):\n",
    "            leftcount=s[:i+1].count('0')\n",
    "            rightcount=s[i+1:].count('1')\n",
    "            score=leftcount+rightcount\n",
    "            if score>max_score:\n",
    "                max_score=score\n",
    "            else:\n",
    "                max_score\n",
    "        return max_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        if s[0]=='0':left=1\n",
    "        else : left=0\n",
    "        right = s[1:].count('1')\n",
    "        res = left + right\n",
    "        for p in range(1,len(s)-1):\n",
    "            if s[p]=='0': left +=1\n",
    "            else: right -=1\n",
    "            if left+right>res:res=left+right\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "      return max(s[:i].count('0') + s[i:].count('1') for i in range(1, len(s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        def findone(nums):\n",
    "            ones=0\n",
    "            for num in nums:\n",
    "                if num == '1':\n",
    "                    ones +=1\n",
    "            return ones\n",
    "        res=0\n",
    "        for i in range(1,len(s)):\n",
    "            right=findone(s[i:])\n",
    "            left=i-findone(s)+right\n",
    "            temp=right+left\n",
    "            res=max(res,temp)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        sn = 0\n",
    "        ans = 0\n",
    "        for i in range(n):\n",
    "            if s[i] == '1':\n",
    "                sn += 1\n",
    "        cnt0, cnt1 = 0, sn\n",
    "        for i in range(n-1):\n",
    "            if s[i] == '0':\n",
    "                cnt0 += 1\n",
    "            else:\n",
    "                cnt1 -= 1\n",
    "            ans = max(ans, cnt0+cnt1)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        list=[]\n",
    "        for i in range(1,len(s)):\n",
    "            score=0 \n",
    "            for j in s[0:i]:\n",
    "                if j == \"0\":\n",
    "                    score += 1\n",
    "            for j in s[i:len(s)+1]:\n",
    "                if j == \"1\":\n",
    "                    score += 1\n",
    "            list.append(score)\n",
    "        return max(list)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans = score = (s[0] == '0') + s[1:].count('1')\n",
    "        for c in s[1:-1]:\n",
    "            score += 1 if c == '0' else -1\n",
    "            ans = max(ans, score)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        one = s.count('1')\n",
    "        zero=0\n",
    "        mcount=0\n",
    "        for i in s[:-1]:\n",
    "            if i =='1':\n",
    "                one-=1\n",
    "            elif i=='0':\n",
    "                zero+=1\n",
    "            mcount=max(mcount,zero+one)\n",
    "        return mcount\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "\n",
    "        a=[]\n",
    "        for i in range(1,len(s)):\n",
    "            a.append(s[:i].count('0')+s[i:].count('1'))\n",
    "        print(a)\n",
    "        return max(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count('0')+s[i:].count('1')for i in range(1,len(s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n=[int(digit) for digit in s]\n",
    "        record=n.copy()\n",
    "        for i in range(len(n)):\n",
    "            n_new=n[:(i+1)]\n",
    "            count_of_zeros = n_new.count(0)\n",
    "            count_of_ones = n_new.count(1)\n",
    "            record[i]=count_of_zeros-count_of_ones\n",
    "        max_index=record.index(max(record))\n",
    "        if max_index<len(record)-1:\n",
    "            index=max_index+1\n",
    "        else:\n",
    "            index=max_index\n",
    "\n",
    "        n_reslut=n[:index]\n",
    "        n_result2=n[index:]\n",
    "        return n_reslut.count(0)+n_result2.count(1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        a = Counter(s)\n",
    "        l,r = 0,a['1']\n",
    "        ans = 0\n",
    "        for i in s[:len(s)-1]:\n",
    "            if i == '0':\n",
    "                l += 1\n",
    "            else:\n",
    "                r -= 1\n",
    "            ans = max(ans,l+r)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[: i].count('0') + s[i: ].count('1') for i in range(1, len(s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans = score = (s[0] == '0') + s[1:].count('1')\n",
    "        for c in s[1:-1]:\n",
    "            score += 1 if c == '0' else -1\n",
    "            ans = max(ans, score)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count('0')+s[i:].count('1') for i in range(1,len(s)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        lists = list(s)\n",
    "        sum=0\n",
    "        if s=='11' or s=='00' :\n",
    "            return 1\n",
    "        elif s=='01':\n",
    "            return 2    \n",
    "        elif s=='10':\n",
    "            return 0\n",
    "        else:        \n",
    "         for i in range(1,len(lists)):\n",
    "            str1 = lists[:i]\n",
    "            str2 = lists[i:]\n",
    "            a = str1.count('0')\n",
    "            b = str2.count('1')\n",
    "            if (a+b)>sum:\n",
    "                sum=a+b\n",
    "         return sum        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count('0') + s[i:].count('1') for i in range(1, len(s)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans=score=(s[0]=='0')+s[1:].count('1')\n",
    "        for c in s[1:-1]:\n",
    "            score +=1 if c==\"0\" else -1\n",
    "            ans=max(ans,score)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        return max(s[:i].count('0') + s[i:].count('1') for i in range(1, len(s)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans = 0\n",
    "        for i in range(1,len(s)):\n",
    "            l = s[:i].count('0')\n",
    "            r = s[i:].count('1')\n",
    "            ans = max(ans, l+r)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        n, presum, ans = len(s), 0, -inf\n",
    "        for i in range(n):\n",
    "            # cur = presum + (n - i - final_presum + presum) = presum * 2 - i + (n - final_presum)\n",
    "            if i and (cur := presum * 2 - i) > ans:\n",
    "                ans = cur\n",
    "            presum += s[i] == \"0\"\n",
    "        return ans + n - presum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        s_len = len(s)\n",
    "\n",
    "        s_max = 0\n",
    "\n",
    "        for i in range(1, s_len):\n",
    "            a = 0\n",
    "            b = 0\n",
    "            for j in range(0, s_len):\n",
    "                if j < i and s[j] == '0':\n",
    "                    a += 1\n",
    "                if j >= i and s[j] == '1':\n",
    "                    b += 1\n",
    "\n",
    "                s_max = max(s_max, a + b)\n",
    "\n",
    "\n",
    "        return s_max"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        s = [int(si) for si in list(s)]\n",
    "        ans = 0\n",
    "        for i in range(1, len(s)):\n",
    "            l = sum([1^items for items in s[:i]])\n",
    "            print(s[:i],s[i:])\n",
    "            r = sum(s[i:])\n",
    "            if l + r > ans:\n",
    "                ans = l + r\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        numbers_str=[*s]\n",
    "        max=0\n",
    "       \n",
    "        for y in range(len(numbers_str)):\n",
    "            counter_0=0\n",
    "            counter_1=0\n",
    "            if y==0:\n",
    "                max=0\n",
    "            else:\n",
    "                \n",
    "                for str_ in numbers_str[:y]:\n",
    "                    if str_=='0':\n",
    "                     counter_0+=1\n",
    "                    \n",
    "                for str_ in numbers_str[y:]:\n",
    "                    if str_=='1':\n",
    "                     counter_1+=1\n",
    "                \n",
    "                if counter_1+counter_0>max:\n",
    "                    max=counter_1+counter_0\n",
    "                    \n",
    "        return max\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        # if len(s) == 2:\n",
    "        #     l = 1 if s[0] == \"0\" else 0\n",
    "        #     r = 1 if s[1] == \"1\" else 0\n",
    "        #     return l+r\n",
    "\n",
    "        ans = 0\n",
    "        for i in range(1, len(s)):\n",
    "            l = Counter(s[:i])[\"0\"]\n",
    "            r = Counter(s[i:])[\"1\"]\n",
    "            ans = max(ans, l + r)\n",
    "        \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxScore(self, s: str) -> int:\n",
    "        ans=0\n",
    "        #ans = float(\"-inf\")\n",
    "        for i in range(1, len(s)):\n",
    "            ans = max(ans, s[:i].count('0') + s[i:].count('1'))\n",
    "        return ans\n",
    "\n",
    "       "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
